from .baseGraphNode import *
from ..execute.baseExeHis import BaseExeHis


class ManualStrGraphNode(BaseGraphNode):
    def __init__(self, id, data, graphNodeManager, random_key):
        super().__init__(id, data, graphNodeManager, random_key)
        self.st = data['data'].get('str','')

        self.executed_num = 1
        
    def get_newest_output_in_session(self, session_info, target_handle):
        st = self.st
        role = "user"
        if 'msg-cat-left' in self.dict['in']:
            msg_cat_left_from = self.dict['in']['msg-cat-left']
            prenode = self.graphNodeManager.nodesByIdDict[msg_cat_left_from['nodeId']]
            msg_cat_left = prenode.get_newest_output_in_session(session_info, msg_cat_left_from['handle'])
            if msg_cat_left is not None:
                role = msg_cat_left.role
                st = str(msg_cat_left.content) + st
        if 'msg-cat-right' in self.dict['in']:
            msg_cat_right_from = self.dict['in']['msg-cat-right']
            prenode = self.graphNodeManager.nodesByIdDict[msg_cat_right_from['nodeId']]
            msg_cat_right = prenode.get_newest_output_in_session(session_info, msg_cat_right_from['handle'])
            if msg_cat_right is not None:
                role = msg_cat_right.role
                st = st + str(msg_cat_right.content)

        return Msg(st, role, "text")

